﻿using System.Windows.Forms;
using Microsoft.Practices.CompositeUI.EventBroker;
using Microsoft.Practices.CompositeUI.WinForms;
using NetRosApp.Infrastructure.Interface;
using NetRosApp.ZajPart.Constants;


namespace NetRosApp.ZajPart
{
   public class ReportWorkItemController:WorkItemController
    {
       [EventSubscription(EventTopicNames.PrikaziIzvjestaj, ThreadOption.UserInterface)]
       public void OnPrikaziIzvjestaj(object sender, EventArgs<object,string> args)
       {
           Cursor.Current = Cursors.WaitCursor;
           ControlledWorkItem<ReportViewWorkItemController> wrptv = WorkItem.WorkItems.Get(args.Data1) as ControlledWorkItem<ReportViewWorkItemController>;
           if (wrptv == null)
           {
               wrptv = WorkItem.WorkItems.AddNew<ControlledWorkItem<ReportViewWorkItemController>>(args.Data1);
               wrptv.Controller.WorkItem.Items.Add(args.Data, "Report");
               wrptv.Controller.WorkItem.Items.Add(args.Data1, "Key");
           }

            wrptv.Controller.Run();
            
       }
       [EventSubscription(EventTopicNames.PrikaziIzvjestajTag, ThreadOption.UserInterface)]
       public void OnPrikaziIzvjestajCustom(object sender, EventArgs<object,string,string> args)
       {
           Cursor.Current = Cursors.WaitCursor;
           ControlledWorkItem<ReportViewWorkItemController> wrptv = WorkItem.WorkItems.Get(args.Data1) as ControlledWorkItem<ReportViewWorkItemController>;
           if (wrptv == null)
           {
               wrptv = WorkItem.WorkItems.AddNew<ControlledWorkItem<ReportViewWorkItemController>>(args.Data1);
               wrptv.Controller.WorkItem.Items.Add(args.Data, "Report");
               wrptv.Controller.WorkItem.Items.Add(args.Data1, "Key");
                wrptv.Controller.WorkItem.Items.Add(args.Data2, "CustomSizes");
           }

            wrptv.Controller.Run();
            
       }
    }

    public class ReportViewWorkItemController : WorkItemController
    {
        public override void Run()
        {
            XtraReportView rptview = WorkItem.SmartParts.Get("XtraReportView") as XtraReportView;
            if (rptview == null)
            {
                rptview = WorkItem.SmartParts.AddNew<XtraReportView>("XtraReportView");
            }
            TabSmartPartInfo spi = new TabSmartPartInfo();
            spi.Title = WorkItem.Items["Key"].ToString();
            WorkItem.Workspaces[WorkspaceNames.RightWorkspace].Show(rptview,spi);
            rptview.Focus();
            Cursor.Current = Cursors.Default;

        }
    }

}
